﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
using Valve.VR.Extras;
//写的一个控制射线关闭开启的功能

public class LaserPointer_MY : MonoBehaviour
{
    public SteamVR_LaserPointer SteamVrLaserPointer;
    /// <summary>
    /// 什么类型的按键 
    /// </summary>
    public SteamVR_Action_Boolean disk;
    void Start()
    {
        if (SteamVrLaserPointer == null)
            SteamVrLaserPointer = this.GetComponent<SteamVR_LaserPointer>();

    }

    void Update()
    {
        //SteamVR_Input_Sources.RightHand 只获取右手的
        if (disk.GetStateDown(SteamVR_Input_Sources.RightHand))
        {
            //按下圆盘开启射线 
            OpenLaserPointer();
        }
        if (disk.GetStateUp(SteamVR_Input_Sources.RightHand))
        {
            //抬起圆盘关闭射线 
            CloseLaserPointer();
        }
    }

    public void OpenLaserPointer()
    {
        GetComponent<SteamVR_LaserPointer>().enabled = true; //射线开启
    }

    public void CloseLaserPointer()
    {
        GetComponent<SteamVR_LaserPointer>().enabled = false; //射线关闭
        GetComponent<SteamVR_LaserPointer>().pointer.transform.localScale = new Vector3(0, 0, 0);
    }
}